//
//  NSString+BankCardFormatter.m
//  minidai
//
//  Created by 容贤郁 on 2018/3/21.
//  Copyright © 2018年 迷你金服. All rights reserved.
//

#import "NSString+BankCardFormatter.h"

@implementation NSString (BankCardFormatter)

- (NSString *)formatterBankCardNum {
    
    NSString *tempStr = self;
    
    NSInteger size =(tempStr.length / 4);
    
    NSMutableArray *tmpStrArr = [[NSMutableArray alloc] init];
    
    for (NSInteger n = 0; n < size; n++) {
        
        [tmpStrArr addObject:[tempStr substringWithRange:NSMakeRange(n * 4, 4)]];
    }
    
    [tmpStrArr addObject:[tempStr substringWithRange:NSMakeRange(size * 4, (tempStr.length % 4))]];
    
    tempStr = [tmpStrArr componentsJoinedByString:@" "];
    
    return tempStr;
}

@end
